/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package plan.mobile;

import java.util.Iterator;
import mobile.Call;
import mobile.Message;
import mobile.MobileConsumption;
import plan.Plan;
import turnover.Consumption;

/**
 *
 * @author Ale
 */
public class Movistar_Contrato_Movistar extends Plan {
private double startQuote = 21.03d;
    private double minuteMovistarCost = 0.03d;
    private double minuteFixedLineAndTypeOneCost = 0.3d;
    private double minuteTypeTwoCost = 0.33d;
    private double messageCost = 0.15d;
    /*Tarifa Plana 24h es compatible con todos los módulos de ahorro
     (a excepción de Fiijos 24h) e incompatible con todas las
     promociones Orange (a excepción de Amigos a 0 y Domingos Orange).*/
    public Movistar_Contrato_Movistar() {
        super.setName("Movistar Contrato Movistar");
    }

    public double getStartQuote() {
        return startQuote;
    }

    @Override
    public double getCost(Consumption consumption) {
        double total = 0d;
        MobileConsumption mc = (MobileConsumption) consumption;
        long duration = 0;
        Iterator it = mc.getCallList().listIterator();
        while (it.hasNext()) {
            Call c = (Call) it.next();


            if (c.isSpecial()) {
                total += c.getCost();

            } else if (c.isMobile() && this.isMovistar(c)) {
                duration += c.getDuration().changeSeconds();
                total += c.getDuration().changeSeconds() * this.minuteMovistarCost / 60;

            } else if (c.isFixedLineTelephone() || this.isOneType(c)) {
                duration += c.getDuration().changeSeconds();
                total += c.getDuration().changeSeconds() * this.minuteFixedLineAndTypeOneCost / 60;
            } else if(this.isTwoType(c)) {
                duration += c.getDuration().changeSeconds();
                total += c.getDuration().changeSeconds() * this.minuteTypeTwoCost / 60;
            }
        }
        it = mc.getMessList().listIterator();
        while (it.hasNext()) {
            Message m = (Message) it.next();
            if (m.isSpecial()) {
                total += m.getCost();
            } else {
                total += this.messageCost;
            }
        }

        if (total<9d){
            total = 9d;
        }

        total += total * 0.16d;
        return total;
    }

    private boolean isMovistar(Call c){
        return c.getOperador().getName().equals("Movistar");
    }

    private boolean isOneType(Call c){
        boolean resA = c.getOperador().getName().equals("Movistar");
        boolean resB = c.getOperador().getName().equals("Yoigo");
        return !(resA || resB);
    }

    private boolean isTwoType(Call c){
        return c.getOperador().getName().equals("Yoigo");
    }

    public double getMessageCost() {
        return messageCost;
    }

}


